package com.zx._12_算法.数据结构.bitmap;

/**
 * @version v1.0
 * @Project: knowledge
 * @Title: SimpleBitMap
 * @Description: 简单实现一个bitMa
 * @author: zhangxue
 * @date: 2019年7月31日下午10:43:24
 * @company: 未知之地
 * @Copyright: Copyright (c) 2019
 */
public class SimpleBitMap implements BitMap {

    int[] datas = new int[101];
    int size = 0;

    public static void main(String[] args) {
        int[] datas = {0, 3, 5, 6, 9, 34, 23, 78, 99};
        BitMap bitMap = new SimpleBitMap();
        for (int i = 0; i < datas.length; i++) {
            bitMap.addMember(datas[i]);
        }

        System.out.println(bitMap.isExist(3));  //true
        System.out.println(bitMap.isExist(7));  //false
        System.out.println(bitMap.isExist(78)); //true
    }

    @Override
    public void addMember(int member) {
        datas[size] = member;
        size++;
    }

    /**
     * 时间复杂度= O(n)
     */
    @Override
    public boolean isExist(int member) {
        boolean isExist = false;
        for (int i = 0; i < size; i++) {
            if (datas[i] == member) {
                isExist = true;
                break;
            }
        }
        return isExist;
    }
}
